package com.aloda.interceptor;

import com.aloda.cache.RedisUtils;
import com.aloda.context.NetUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class RecordInterceptor implements HandlerInterceptor {

    @Resource
    private RedisUtils redisUtils;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String ip = NetUtils.getIpAddress(request);
        redisUtils.savePV();
        redisUtils.saveUV(ip);
        return true;
    }
}
